package com.lorenzogao.latte_core.net

import com.lorenzogao.latte_core.app.ConfigType
import com.lorenzogao.latte_core.app.Latte
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.util.concurrent.TimeUnit

/**
 *  create by LorenzoGao
 *  email: 2508719070@qq.com
 *  TIME: 2020-01-08 11:44
 *  description:
 */

class RestCreator {

    companion object {

        val PARAMS by lazy {
            mutableMapOf<String,Any>()
        }

        private val OK_HTTP_CLIENT by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            val TIME_OUT = 60L
            return@lazy OkHttpClient.Builder()

                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .build()


        }

        private val RETROFIT_CLIENT by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            val BASE_URL = Latte.getConfigurators()[ConfigType.API_HOST.name] as String
            return@lazy Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(OK_HTTP_CLIENT)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build()
        }


        val getRestService by lazy {
            RETROFIT_CLIENT.create(RestService::class.java)
        }


    }


}